import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'
import Pages from 'vite-plugin-pages'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
const path = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  /** 打包配置二级路径 */
  // base: 'readiness',
  plugins: [
    vue({
      reactivityTransform: true,
    }),
    Pages({
      dirs: 'src/views',
    }),
    vueJsx(),
    AutoImport({
      imports: ['vue', 'vue/macros', 'vue-router', '@vueuse/core'],
      dts: true,
      dirs: ['src/store/modules', 'src/service/api'],
    }),
    // ui库解析器，也可以自定义
    Components({
      // allow auto load markdown components under `./src/components/`
      extensions: ['vue', 'md'],
      // allow auto import and register components used in markdown
      include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
      dts: 'src/components.d.ts',
    }),
    Unocss(),
  ],
  resolve: {
    alias: {
      '~': path.resolve('./'),
      '@': path.resolve(__dirname, 'src'),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve('src/styles/theme.less')}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
  server: {
    host: '0.0.0.0',
    port: 3000,
    open: true,
    // proxy: {
    //   '/xfjg-jyjg-model': {
    //     target: 'http://192.168.3.101:8401',
    //     changeOrigin: true,
    //     rewrite: (path) => path.replace(/^\/xfjg-jyjg-model/, ''), // 重写路径把路径变成空字符
    //   },
    // },

    // 代理设置
    // proxy: {
    //   '/api': {
    //     target: 'http://httpbin.org',
    //     rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径把路径变成空字符
    //   },
    // },
  },
})
